//
//  ACTabbarViewController.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/29.
//

#import "ACTabbarViewController.h"
#import "ACLiveMianViewController.h"
#import "ACMeetingViewController.h"
#import "ACVodPlayViewController.h"
#import "ACMineViewController.h"
#import "ACNavigationController.h"


@interface ACTabbarViewController ()

@end

@implementation ACTabbarViewController


- (void)viewDidLoad{
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    self.fd_interactivePopDisabled = YES;
    self.fd_interactivePopMaxAllowedInitialDistanceToLeftEdge = 200;
    
    [self.tabBar setTranslucent:NO];
    [self setupController];
}
-(void)setupController{
    ACNavigationController *liveVC = [self setupTabbarItemWithController:[ACLiveMianViewController new] title:@"直播" image: [UIImage imageWithName:@"live_home" bundle:ACLiteAVUISDK targetClass:[self class]] selectedImage: [UIImage imageWithName:@"live_home_selected" bundle:ACLiteAVUISDK targetClass:[self class]]];
    ACNavigationController *meetingVC = [self setupTabbarItemWithController:[ACMeetingViewController new] title:@"会议" image: [UIImage imageWithName:@"meeting_home" bundle:ACLiteAVUISDK targetClass:[self class]] selectedImage: [UIImage imageWithName:@"meeting_home_selected" bundle:ACLiteAVUISDK targetClass:[self class]]];
    ACNavigationController *vodPlayVC = [self setupTabbarItemWithController:[ACVodPlayViewController new] title:@"点播视频" image: [UIImage imageWithName:@"video_home" bundle:ACLiteAVUISDK targetClass:[self class]] selectedImage: [UIImage imageWithName:@"video_home_selected" bundle:ACLiteAVUISDK targetClass:[self class]]];
    ACNavigationController *mineVC = [self setupTabbarItemWithController:[ACMineViewController new] title:@"我的" image: [UIImage imageWithName:@"mine_home" bundle:ACLiteAVUISDK targetClass:[self class]] selectedImage: [UIImage imageWithName:@"mine_home_selected" bundle:ACLiteAVUISDK targetClass:[self class]]];
    self.viewControllers = @[liveVC,meetingVC,vodPlayVC,mineVC];
    
}
-(ACNavigationController *)setupTabbarItemWithController:(UIViewController *)VC  title:(NSString *)title image:(UIImage *)imge selectedImage:(UIImage *)selectedImage{
    
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:title image:imge selectedImage:selectedImage];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x909399)} forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFF6048)} forState:UIControlStateSelected];
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]} forState:UIControlStateNormal];
    VC.tabBarItem = item;
    self.tabBar.tintColor = UIColorFromRGB(0xFF6048);
    ACNavigationController *naVC = [[ACNavigationController alloc] initWithRootViewController:VC];
    naVC.tabBarItem.title = title;
    return naVC;
}

-(RACSignal<NSNumber * >*)autoLoginToV2IM{
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        [TRTCLiveRoomIMAction loginWithUserID:[ACUserProfileManager shareInstance].userModel.phone userSig: [[ACUserProfileManager shareInstance] getUserSig] callback:^(int code, NSString * _Nonnull message) {
            if (code == 0) {
                // 成功
                DDLogInfo(@"Im denglu chengg l ");
                [subscriber sendNext:[NSNumber numberWithBool:YES]];
                [subscriber sendCompleted];
            }else{
                // 失败
                DDLogInfo(@"autoLoginToV2IMFailed");
                NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:code userInfo:nil];
                [subscriber sendError:error];
            }
        }];
        return nil;
    }];
    return signal;
}
@end
